package cn.edu.usst.cs.goldfish.booking.meetingroom.typehandler;

import cn.edu.usst.cs.goldfish.booking.meetingroom.model.enums.MeetingStatus;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.CallableStatement;
import java.sql.SQLException;

@MappedTypes(MeetingStatus.class)
@MappedJdbcTypes(JdbcType.OTHER)
public class MeetingStatusTypeHandler extends BaseTypeHandler<MeetingStatus> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, MeetingStatus parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.name());
    }

    @Override
    public MeetingStatus getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String value = rs.getString(columnName);
        return value == null ? null : MeetingStatus.valueOf(value);
    }

    @Override
    public MeetingStatus getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String value = rs.getString(columnIndex);
        return value == null ? null : MeetingStatus.valueOf(value);
    }

    @Override
    public MeetingStatus getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String value = cs.getString(columnIndex);
        return value == null ? null : MeetingStatus.valueOf(value);
    }
} 